﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_EditMovie : System.Web.UI.Page
{
    Product pd = new Product();
    protected void Page_Load(object sender, EventArgs e)
    {
        if(IsPostBack==false)
        {
        DateTime day = new DateTime();
        day = DateTime.Now.Date;
        grvData.DataSource = pd.GetMovieY(day);
        grvData.DataBind();
        grvData0.DataSource = pd.GetMovie(day);
        grvData0.DataBind();
        }
    }
    protected void btnOption_Click(object sender, System.Web.UI.WebControls.CommandEventArgs e)
    {
        try
        {
            string opt = e.CommandName;
            string id = (string)e.CommandArgument;
            int i = int.Parse(id);
            Label la = (Label)(grvData.Rows[i].FindControl("lblMovieID"));
            string movieid = la.Text.Trim();
            if (opt.Equals("Edit"))
            {
                Session["MVID"] = movieid;
                Response.Redirect("EditMovieByID.aspx");

            }
            else if (opt.Equals("Delete"))
            {
                lblError.Visible = true;
                lblError.Text = pd.DelMovie(movieid);
                DateTime day = new DateTime();
                day = DateTime.Now.Date;
                grvData.DataSource = pd.GetMovieY(day);
                grvData.DataBind();
            }
        }
        catch (Exception)
        {
        }
    }
    protected void btnOption0_Click(object sender, System.Web.UI.WebControls.CommandEventArgs e)
    {
        string opt = e.CommandName;
        string id = (string)e.CommandArgument;
        int i = int.Parse(id);
        Label la = (Label)(grvData0.Rows[i].FindControl("lblMovieID0"));
        string mvid = la.Text.Trim();
        if (opt.Equals("Edit"))
        {
            Session["MVID"] = mvid;
            Response.Redirect("EditMovieByID.aspx");

        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("AddMovie.aspx");
    }
    protected void btnSearch0_Click(object sender, EventArgs e)
    {
        if ("" != TextBox2.Text.Trim())
        {
            grvData0.DataSource = pd.GetMovieByName(TextBox2.Text.Trim());
            grvData0.DataBind();
        }
        else
        {
            lblError1.Visible = true;
            lblError1.Text = "Enter movies name!";
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if ("" != TextBox1.Text.Trim())
        {
        grvData.DataSource = pd.GetMovieByName(TextBox1.Text.Trim());
        grvData.DataBind();
        }
        else
        {
            lblError2.Visible = true;
            lblError2.Text = "Enter movies name!";
        }
    }
    protected void grvData_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvData.PageIndex = e.NewPageIndex;
        DateTime day = new DateTime();
        day = DateTime.Now.Date;
        grvData.DataSource = pd.GetMovieY(day);
        grvData.DataBind();
    }
    protected void grvData0_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvData.PageIndex = e.NewPageIndex;
        DateTime day = new DateTime();
        day = DateTime.Now.Date;
        grvData0.DataSource = pd.GetMovie(day);
        grvData0.DataBind();
    }
}